<template>
  <div class="login-container">
    <div class="banner-1">
      <div class="title">登录页设置</div>
      <div class="right">
        <el-button size="mini" @click="cancel">取消</el-button>
        <el-button type="primary" size="mini" @click="submit">保存</el-button>
      </div>
    </div>
    <div class="banner-2">
      <div class="list">
        <div class="label">背景图：</div>
        <div class="value">{{ updateInfos.name }}</div>
      </div>
      <el-button type="primary" size="mini" @click="btn">上传</el-button>
      <input
        ref="input"
        type="file"
        style="display: none"
        @change="uplaodPic($event)"
        :key="fileKey"
      />
    </div>
    <div class="login-container">
      <myLogin :imageUrl="imageUrl"/>
    </div>
  </div>
</template>

<script>
import myLogin from "@/views/login";
import request from "@/utils/request";
import Qs from "qs";
export default {
  components: {
    myLogin,
  },
  data() {
    return {
      fileKey: "updata1",
      updateInfos: {},
      imageUrl:'',
    };
  },
  created() {
    this.getImage();
  },
  methods: {
    btn() {
      this.$refs.input.click();
    },
    getImage() {
      request({
        url: "/system/company/getCompanyInfo",
        method: "post",
        headers: {
          isToken: false,
        },
      }).then((res) => {
        console.log(res);
      });
    },
    async uplaodPic(e) {
      const timer = window.setTimeout(() => {
        this.fileKey = `${new Date().getTime()}`;
        window.clearTimeout(timer);
      }, 1000);
      this.updateInfos = e.target.files[0];
      const params = new FormData();
      params.append("file", this.updateInfos);
      request({
        url: "/common/upload",
        method: "post",
        data: params,
        headers: {
          "Content-Type": "application/json;charset=UTF-8",
        },
      }).then((res) => {
        this.$message({
          type: "success",
          message: "上传成功!",
        });
        this.imageUrl=res.url
        console.log(res);
      });
      // this.imageUrl=imageUrl
      // console.log(imageUrl);
    },
    submit() {
      request({
        url: "/system/company/edit",
        method: "post",
        headers: {
          isToken: false,
        },
        // headers: { "content-type": "application/x-www-form-urlencoded" },
        data: {
          id:1,
          companyAddr:this.imageUrl,
        },
      }).then((res) => {
        this.$message({
          type: "success",
          message: "保存成功!",
        });
      })
    },
    cancel() {},
  },
};
</script>

<style scoped lang="scss">
.login-container {
  width: 100%;

  .banner-1 {
    width: 100%;
    height: 50px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
  }

  .banner-2 {
    width: 100%;
    height: 50px;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding: 0 40px;

    .list {
      display: flex;
      flex-direction: row;
      align-items: center;
      padding-right: 20px;
    }
  }

  .login-container {
    width: 100%;
    overflow-x: auto;

    ::v-deep {
      .content {
        transform: scale(0.8);
        transform-origin: left top;
      }
    }
  }
}
</style>